package git.bds.nyc.communal.service.audit.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import git.bds.nyc.communal.mapper.mp.audit.AuditFarmerDemandMapper;
import git.bds.nyc.communal.model.domain.audit.AuditFarmerDemand;
import git.bds.nyc.communal.service.audit.AuditFarmerDemandService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 审核个人发布的需求 服务实现类
 * </p>
 *
 * @author 成大事
 * @since 2022-11-23 10:43:48
 */
@Service
public class AuditFarmerDemandServiceImpl extends MPJBaseServiceImpl<AuditFarmerDemandMapper, AuditFarmerDemand> implements AuditFarmerDemandService {


    /**
     * 添加审核
     *
     * @param id        身份证件
     * @param demandId 产品id
     * @return {@link Boolean}
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addAudit(long id, long demandId) {
        AuditFarmerDemand auditFarmerDemand = new AuditFarmerDemand().setUserId(id).setDemandId(demandId);
        return this.baseMapper.insert(auditFarmerDemand) > 0;
    }

    /**
     * 按需求id删除发布的需求
     *
     * @param id 需求id
     * @return {@link Boolean}
     */
    @Override
    public Boolean delDemandById(Long id) {
        return this.baseMapper.delete(new LambdaQueryWrapper<AuditFarmerDemand>().eq(AuditFarmerDemand::getDemandId,id)) > 0;
    }
}
